/**
 * Created by lt on 2017/5/10.
 */
$(function () {

    $("#productAdd").click(function () {
        $("#form-product-add").ajaxSubmit({
            type: "POST",
            url: '/product/modifyProduct.html',
            data: $('#form-product-add').serialize(),// 你的formid
            dataType:"json",
            error: function (request) {
                alert("Connection error");
            },
            beforeSend: function () {
                console.log("begin...............");
                $(".loading").show();

            },
            success: function (data) {
                console.log(data);
                if (data.code != 0) {
                    layer.msg('添加成功!', {icon: 6, time: 1000}, function () {
                        console.log(data);
                        window.parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    })
                }

            },
            complete: function (XMLHttpRequest, textStatus) {
                // alert('远程调用成功，状态文本值：'+textStatus);
                console.log("end...............");
                $(".loading").hide();
            },
        });

    });


    $("#productEntityAdd").click(function () {
        var price = $("#price").val();
        $("#price").val(price*100);
        $("#form-productEntity-add").ajaxSubmit({
            type: "POST",
            url: '/productEntity/modifyProductEntity.html',
            data: $('#form-productEntity-add').serialize(),// 你的formid
            dataType:"json",
            error: function (request) {
                alert("Connection error");
            },
            beforeSend: function () {
                console.log("begin...............");
                $("#loading").show();
                $("#mask").show();

            },
            success: function (data) {
                console.log(data);
                if (data.code != 0) {
                    layer.msg('添加成功!', {icon: 6, time: 1000}, function () {
                        console.log(data);
                        window.parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    })
                }

            },
            complete: function (XMLHttpRequest, textStatus) {
                // alert('远程调用成功，状态文本值：'+textStatus);
                console.log("end...............");
                $("#loading").hide();
                $("#mask").hide();
            },
        });

    })
});


function stopProduct(productId){
    $.ajax({
        type: "POST",
        url: '/product/stopProduct.html',
        data: {"productId":productId},// 你的formid
        dataType:"json",

        success: function (data) {
            console.log(data);
            if (data.code != 0) {
                layer.msg('停用成功!', {icon: 6, time: 1000}, function () {
                    console.log(data);
                    window.location.reload();
                })
            }

        },
    });
}
function operateProduct(productId){
    $.ajax({
        type: "POST",
        url: '/product/operateProduct.html',
        data: {"productId":productId},// 你的formid
        dataType:"json",

        success: function (data) {
            console.log(data);
            if (data.code != 0) {
                layer.msg('启用成功!', {icon: 6, time: 1000}, function () {
                    console.log(data);
                    window.location.reload();
                })
            }

        },
    });
}

function stopProductEntity(tid){
    $.ajax({
        type: "POST",
        url: '/productEntity/stopProductEntity.html',
        data: {"tid":tid},// 你的formid
        dataType:"json",

        success: function (data) {
            console.log(data);
            if (data.code != 0) {
                layer.msg('停用成功!', {icon: 6, time: 1000}, function () {
                    console.log(data);
                    window.location.reload();
                })
            }

        },
    });
}
function operateProductEntity(tid){
    $.ajax({
        type: "POST",
        url: '/productEntity/operateProductEntity.html',
        data: {"tid":tid},// 你的formid
        dataType:"json",

        success: function (data) {
            console.log(data);
            if (data.code != 0) {
                layer.msg('启用成功!', {icon: 6, time: 1000}, function () {
                    console.log(data);
                    window.location.reload();
                })
            }

        },
    });
}


